// 三进制

#include <bits/stdc++.h>

const int MAXN = 10 + 5;
const int MAXM = 100 + 5;
int n, m;
int c[MAXN];
int k[MAXM], a[MAXM][MAXN];
int pw[MAXN];

int v[MAXN]; // 每个动物园看了几次
long long ans = 1e18;

int main() {
  scanf("%d%d", &n, &m);
  pw[0] = 1;
  for (int i = 1; i <= n; ++i)
    pw[i] = pw[i - 1] * 3;

  for (int i = 1; i <= n; ++i)
    scanf("%d", &c[i]);
  for (int i = 1; i <= m; ++i) {
    scanf("%d", k + i);
    for (int j = 1; j <= k[i]; ++j) {
      scanf("%d", &a[i][j]);
    }
  }
  for (int S = 0; S < pw[n]; ++S) {
    long long sum = 0;
    for (int i = 0; i < n; ++i) {
      v[i + 1] = (S / pw[i]) % 3;
      sum += c[i + 1] * v[i + 1];
    }

    bool flag = false;
    for (int i = 1; i <= m; ++i) {
      int cnt = 0;
      for (int j = 1; j <= k[i]; ++j) {
        cnt += v[a[i][j]];
      }
      if (cnt < 2) {
        flag = true;
        break;
      }
    }
    if (flag)
      continue;
    ans = std::min(ans, sum);
  }
  printf("%lld\n", ans);
  return 0;
}